﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.Model;
using rock.DAL;
using rock.UI.common;
using rock.BLL;

namespace rock.UI.houseinfo
{
    public partial class FormHouseXiaoquUpdate : Form
    {
        ModelHOUSE_XIAOQU modelHOUSE_XIAOQU = new ModelHOUSE_XIAOQU() ;
        public ModelHOUSE_XIAOQU _ModelHOUSE_XIAOQU
        {
            get
            {
                return modelHOUSE_XIAOQU;
            }
            set
            {
                modelHOUSE_XIAOQU = value;
            }
        }


        DalHOUSE_XIAOQU dalHOUSE_XIAOQU = new DalHOUSE_XIAOQU();
        DalCFG_CODE dalCFG_CODE = new DalCFG_CODE();
        public FormHouseXiaoquUpdate()
        {
            InitializeComponent();
            this.AcceptButton = this.button1;
            this.CancelButton = this.button2;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = global::rock.Properties.Resources.house;
        }
        private void FormHouseXiaoquUpdate_Load(object sender, EventArgs e)
        {
            this.textBox1Name.Text = this._ModelHOUSE_XIAOQU.NAME;
           // this.textBox2CreateHouse.Text = this._ModelHOUSE_XIAOQU.CREATE_HOUSE;


            DataSet cfgCodeSet = this.dalCFG_CODE.GetList("TYPE = '开发商'");
            this.comboBox1.DisplayMember = "CODE_VALUE";
            this.comboBox1.ValueMember = "CODE_VALUE";
            this.comboBox1.DataSource = cfgCodeSet.Tables[0];
            if (this._ModelHOUSE_XIAOQU.CREATE_HOUSE != null && !this._ModelHOUSE_XIAOQU.CREATE_HOUSE.Equals(""))
            {
                this.comboBox1.SelectedValue = this._ModelHOUSE_XIAOQU.CREATE_HOUSE;
            }
            else
            {
                this.comboBox1.SelectedIndex = 0;

            }


        }
        private Boolean check()
        {
            try
            {
                StringUtils.checkText(this.textBox1Name.Text, 2, 30, "市场名称");

                //更新.原值不检测
                if (dalHOUSE_XIAOQU.Exists(this._ModelHOUSE_XIAOQU.SEQID))
                {
                    if (this._ModelHOUSE_XIAOQU.NAME.Equals(this.textBox1Name.Text.Trim()))
                    {
                        return true;
                    }
                }
                String existSql = "select count(1) from HOUSE_XIAOQU where NAME = '{0}'";
                existSql = String.Format(existSql, this.textBox1Name.Text);
                if (BllCommonUtil.Exists(existSql))
                {
                    MessageBox.Show("此市场名称值已存在在,请输入其它的值");
                    return false;
                }


            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "提示");
                return false;
            }
            return true;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (!check())
            {
                return;
            }

            this._ModelHOUSE_XIAOQU.NAME = this.textBox1Name.Text;
            this._ModelHOUSE_XIAOQU.CREATE_HOUSE = (String)this.comboBox1.SelectedValue;


            if (dalHOUSE_XIAOQU.Exists(this._ModelHOUSE_XIAOQU.SEQID))
            {
                dalHOUSE_XIAOQU.Update(this._ModelHOUSE_XIAOQU);
            }
            else
            {
                dalHOUSE_XIAOQU.Add(this._ModelHOUSE_XIAOQU);
            }
            //触发代理
            oneRefreshParentData();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //代理
        public delegate void RefreshParentData();
        public RefreshParentData oneRefreshParentData;

        
    }
}
